<template>
  <div class="boxsty zhiBiao">
    <div
      :height="searchheight"
      v-if="programInterface != 'fqtb' && programInterface != 'jgtb'"
    >
      <span
        style="float: right; margin-top: -30px; cursor: pointer"
        @click="searchchangeadvanced"
        >{{ searchadvanced ? "收起" : "展开" }}
        <i
          :class="searchadvanced ? 'el-icon-arrow-up' : 'el-icon-arrow-down'"
        />
      </span>
      <div v-show="searchadvanced">
        <contractDetailHeader
          :contractDetailHeaderData="hetongzhibiaoTable.rows"
        ></contractDetailHeader>
      </div>
      <div v-show="searchadvanced">
        <el-form
          :inline="true"
          :model="dataForm"
          @keyup.enter.native="getDataList()"
          class="form-inline"
          v-if="showSearch"
        >
          <el-form-item label="指标名称">
            <el-input
              v-model="dataForm.zhibiaoName"
              placeholder="指标名称"
              :clearable="true"
            ></el-input>
          </el-form-item>
          <el-form-item label="指标类别">
            <el-input
              v-model="dataForm.zhibiaoType"
              placeholder="指标类别"
              :clearable="true"
            ></el-input>
          </el-form-item>
          <el-form-item>
            <el-button
              icon="el-icon-search"
              type="primary"
              class="marginLeft"
              @click="getDataList(1)"
              >检索
            </el-button>
          </el-form-item>
        </el-form>
      </div>
    </div>

    <div
      style="display: flex; justify-content: space-between; margin: 0 auto"
      class="table-header-btn-box"
    >
      <!-- <div>
        <el-button
          plain
          v-if="hetongzhibiaoTable.type == 'jgtb'"
          type="primary"
          @click="showZhibiaoTable"
          >指标库</el-button
        >
      </div> -->
      <div
        style="display: flex; justify-content: flex-end"
        v-if="
          (lastPage == 'tbfq' || lastPage == 'jgtb') &&
          programInterface != 'fqtb'
        "
      >
        <span v-if="hetongzhibiaoTable.isEditRow" class="mg-r10">
          <el-button
            plain
            type="primary"
            v-if="
              (lastPage == 'jgtb' && hetongzhibiaoTable.jgtbstatus == 11) ||
              (lastPage == 'tbsh' && hetongzhibiaoTable.jgtbstatus == 12)
            "
            >数据获取</el-button
          >
          <el-button
            plain
            type="primary"
            @click="openSubmitAllDialog"
            v-if="
              (lastPage == 'jgtb' && hetongzhibiaoTable.jgtbstatus == 11) ||
              (lastPage == 'tbsh' && hetongzhibiaoTable.jgtbstatus == 12)
            "
            >批量提交</el-button
          >
        </span>

        <el-upload
          class="upload-demo"
          action="/admin/sys-file/upload"
          accept=".xls,.xlsx"
          :headers="headers"
          :before-upload="beforeFileUpload"
          :on-change="handleChange"
          :on-success="handleUploadSuccess"
          :show-file-list="false"
          :file-list="fileList"
        >
          <el-button type="primary">导入</el-button>
        </el-upload>
        <span class="mg-r10">
          <el-button
            plain
            type="primary"
            style="margin-left: 10px"
            @click="exportExcel"
            >导出</el-button
          >
          <el-button
            plain
            type="primary"
            style="margin-left: 10px"
            @click="fnBackOldPage('返回原页面')"
            >返回</el-button
          >
        </span>
      </div>
      <div v-if="programInterface == 'fqtb'">
        <el-button plain type="primary" @click="fnBackOldPage('返回原页面')"
          >返回</el-button
        >
      </div>
      <div
        class="table-header-btn-box"
        v-if="lastPage == 'jghz' || lastPage == 'qtjc'"
      >
        <el-button plain type="primary" style="float: right"
          >添加指标</el-button
        >
      </div>
    </div>
    <div class="avue-crud">
      <div class="flex" v-if="pageTitle == '业绩合同'"></div>
      <el-table
        ref="reftable"
        style="width: 100%; margin-top: 20px"
        :data="dataList"
        border
        v-loading="dataListLoading"
      >
        <!--        <el-table-column type="selection" :selectable='checkboxSelect' width="55" header-align="center" align="center"></el-table-column>-->
        <el-table-column
          type="index"
          width="80"
          header-align="center"
          align="center"
          label="序号"
        ></el-table-column>
        <el-table-column
          prop="shouyueName"
          header-align="center"
          align="center"
          min-width="130"
          v-if="hetongzhibiaoTable.radioType == '1'"
          label="受约人姓名"
        >
        </el-table-column>
        <el-table-column
          v-if="hetongzhibiaoTable.radioType == '2'"
          prop="dataProvider"
          header-align="center"
          align="center"
          min-width="130"
          label="机构名称"
        >
        </el-table-column>
        <el-table-column
          prop="zhibiaoType"
          header-align="center"
          align="center"
          min-width="100"
          label="指标类别"
        >
        </el-table-column>
        <el-table-column
          prop="zhibiaoName"
          header-align="center"
          align="center"
          min-width="100"
          label="指标名称"
          show-overflow-tooltip
        >
        </el-table-column>
        <el-table-column
          prop="auditStatus"
          header-align="center"
          align="center"
          min-width="100"
          label="状态"
          :formatter="tbzbStatusFormater"
        >
        </el-table-column>
        <el-table-column
          prop="weight"
          header-align="center"
          align="center"
          label="权重"
        >
        </el-table-column>
        <el-table-column
          prop="formulaId"
          label="计算公式"
          min-width="180"
          header-align="center"
          align="center"
        >
          <template slot-scope="scope">
            <span v-if="scope.row.formulaId == null">无公式</span>
            <div v-else v-for="(item, index) in formulaOptions" :key="index">
              <span v-if="item.id == scope.row.formulaId">{{ item.gsMc }}</span>
            </div>
          </template>
        </el-table-column>
        <el-table-column
          prop="targetValue"
          header-align="center"
          align="center"
          label="目标值"
        >
        </el-table-column>
        <el-table-column
          prop="unit"
          header-align="center"
          align="center"
          label="单位"
        >
        </el-table-column>
        <el-table-column
          prop="ytbSz"
          label="填报值(预)"
          min-width="120"
          header-align="center"
          align="center"
        >
          <template slot-scope="scope">
            <span
              v-if="
                (lastPage == 'tbfq' && scope.row.contractAuditStatus == 10) ||
                (hetongzhibiaoTable.type == 'jgtb' &&
                  hetongzhibiaoTable.isEditRow &&
                  scope.row.zhibiaoType != '奖惩类') ||
                (lastPage == 'tbsh' && scope.row.contractAuditStatus == 12) ||
                (hetongzhibiaoTable.jgtbstatus == 111 &&
                  scope.row.auditStatus != 5)
              "
            >
              <el-input
                v-model="scope.row.ytbSz"
                :disabled="hetongzhibiaoTable.operationType == 1"
                size="mini"
                placeholder="请输入内容"
                @change="saveProperty(scope.row, scope.$index)"
              />
            </span>
            <span v-else>{{ scope.row.ytbSz }}</span>
          </template>
        </el-table-column>
        <el-table-column
          prop="tbSz"
          label="填报值"
          min-width="120"
          header-align="center"
          align="center"
        >
          <template slot-scope="scope">
            <span
              v-if="
                (lastPage == 'tbfq' && scope.row.contractAuditStatus == 10) ||
                (hetongzhibiaoTable.type == 'jgtb' &&
                  hetongzhibiaoTable.isEditRow &&
                  scope.row.zhibiaoType != '奖惩类') ||
                (lastPage == 'tbsh' && scope.row.contractAuditStatus == 12) ||
                (hetongzhibiaoTable.jgtbstatus == 111 &&
                  scope.row.auditStatus != 5)
              "
            >
              <el-input
                v-model="scope.row.tbSz"
                :disabled="hetongzhibiaoTable.operationType == 0"
                size="mini"
                placeholder="请输入内容"
                @change="saveProperty(scope.row, scope.$index)"
              />
            </span>
            <span v-else>{{ scope.row.tbSz }} </span>
          </template>
        </el-table-column>
        <el-table-column
          prop="zbDf"
          header-align="center"
          align="center"
          label="得分"
        >
          <template slot-scope="scope">
            <el-popover placement="left" width="300" trigger="hover">
              <!-- <p>考核得分：10</p>
              <p>加扣情况：-2</p>
              <p>加扣原因：迟到</p> -->
              <div style="margin: 10px 5px">
                <div
                  v-for="(item, index) in scope.row.suspensionList"
                  :key="index"
                >
                  <span style="color: #0bbf4a">{{ item }}</span>
                </div>
              </div>

              <div slot="reference" class="name-wrapper">
                <!-- <span v-if ="scope.row.formulaId != null " style="color:#ff3300">{{scope.row.zbDf}}</span> -->
                <span
                  v-if="
                    (lastPage == 'tbfq' &&
                      scope.row.contractAuditStatus == 10) ||
                    (hetongzhibiaoTable.type == 'jgtb' &&
                      hetongzhibiaoTable.isEditRow &&
                      scope.row.zhibiaoType != '奖惩类') ||
                    (lastPage == 'tbsh' &&
                      scope.row.contractAuditStatus == 12) ||
                    (hetongzhibiaoTable.jgtbstatus == 111 &&
                      scope.row.auditStatus != 5)
                  "
                >
                  <el-input
                    v-model="scope.row.zbDf"
                    placeholder="请输入内容"
                    @change="saveProperty(scope.row, scope.$index)"
                  />
                </span>
                <span v-else style="color: #ff3300">{{ scope.row.zbDf }}</span>
              </div>
            </el-popover>
          </template>
        </el-table-column>
        <el-table-column
          v-if="lastPage != 'jghz' && lastPage != 'qtjc'"
          prop="signLevel"
          header-align="center"
          align="center"
          min-width="100"
          label="合同级别"
          :formatter="statusFormater"
        >
        </el-table-column>
      </el-table>
    </div>
    <div class="avue-crud__pagination">
      <el-pagination
        @size-change="sizeChangeHandle"
        @current-change="currentChangeHandle"
        :current-page="pageIndex"
        :page-sizes="[10, 20, 50, 100]"
        :page-size="pageSize"
        :total="totalPage"
        background
        layout="total, sizes, prev, pager, next, jumper"
      >
      </el-pagination>
    </div>
    <div class="text-center" v-if="showBackBtn"></div>
    <el-dialog
      title="输入加扣原因"
      :visible.sync="visible"
      width="700px"
      @close="closeDialog"
    >
      <div>
        <el-form :model="dataFormjia" ref="dataFormjia" label-width="130px">
          <div class="boxsty">
            <div v-if="[1, 2, 5].includes(status)">
              <el-row>
                <el-col>预填报阶段</el-col>
              </el-row>
              <el-row>
                <el-col :span="24">
                  <el-form-item label="加扣分值">
                    <el-input v-model="dataFormjia.ytbSzfrac"></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="24">
                  <el-form-item label="加扣原因">
                    <el-input
                      type="textarea"
                      :rows="4"
                      v-model="dataFormjia.ytbSzfracre"
                    ></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
            </div>
            <div v-if="[3, 4, 6].includes(status)">
              <el-row>
                <el-col>填报阶段</el-col>
              </el-row>
              <el-row>
                <el-col :span="24">
                  <el-form-item label="加扣分值">
                    <el-input v-model="dataFormjia.tbSzfrac"></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="24">
                  <el-form-item label="加扣原因">
                    <el-input
                      type="textarea"
                      :rows="4"
                      v-model="dataFormjia.tbSzfracre"
                    ></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
            </div>
          </div>
        </el-form>
      </div>
      <span slot="footer">
        <el-button
          plain
          type="primary"
          size="small"
          @click="dataFormjiaSubmit(dataFormjia)"
          >确认保存</el-button
        >
        <el-button plain size="small" @click="closeDialog">关闭窗口</el-button>
      </span>
    </el-dialog>

    <el-dialog
      title="输入加扣原因"
      :visible.sync="visiblejiakou"
      width="700px"
      @close="closeDialogAll"
    >
      <div>
        <el-form
          :model="dataFormjiakou"
          ref="dataFormjiakou"
          label-width="130px"
        >
          <div class="boxsty">
            <div>
              <el-row>
                <el-col :span="24">
                  <el-form-item label="加扣分值">
                    <el-input v-model="dataFormjiakou.tbSzfracs"></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="24">
                  <el-form-item label="加扣原因">
                    <el-input
                      type="textarea"
                      :rows="4"
                      v-model="dataFormjiakou.tbSzfracres"
                    ></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
            </div>
          </div>
        </el-form>
      </div>
      <span slot="footer">
        <el-button
          type="primary"
          plain
          size="small"
          @click="dataFormjiaSubmitAll(dataFormjiakou)"
          >确认保存</el-button
        >
        <el-button plain size="small" @click="closeDialogAll"
          >关闭窗口</el-button
        >
      </span>
    </el-dialog>
    <!--     批量提交弹框 -->
    <el-dialog title="提示" :visible.sync="dialogVisiblePiLiang" width="30%">
      <div>
        <el-form :model="pilinangform">
          <el-form-item label="会签人员">
            <el-input
              v-model="pilinangform.sonhq"
              placeholder="会签人员"
            ></el-input>
          </el-form-item>
          <span>请按审批顺序输入会签人员，请用逗号【,】隔开</span>
        </el-form>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button plain type="primary" @click="handleSubmitAll"
          >确 定</el-button
        >
        <el-button plain @click="dialogVisiblePiLiang = false">取 消</el-button>
      </span>
    </el-dialog>
    <el-dialog title="请选择：" :visible.sync="chooseVisible" width="30%">
      <div style="display: flex; justify-content: space-around">
        <el-button plain type="warning" @click="customBtn"
          >自定义流程</el-button
        >
        <!-- <el-button plain type="primary" @click="temBtn" v-loading.fullscreen.lock="fullscreenLoading">模板</el-button> -->
        <el-dropdown>
          <el-button plain type="primary" size="small">
            模板<i class="el-icon-arrow-down el-icon--right"></i>
          </el-button>
          <el-dropdown-menu v-if="temList.length > 0">
            <el-dropdown-item v-for="(item, k) in temList" :key="k"
              ><span @click="temBtn(item)">{{
                item.templateName
              }}</span></el-dropdown-item
            >
          </el-dropdown-menu>
        </el-dropdown>
      </div>
    </el-dialog>
    <sortingPerChooseDialog
      :sortingPerChooseDialogData="sortingPerChooseDialogData"
      @sortingPerChooseDialogChild="sortingPerChooseDialogChild"
    ></sortingPerChooseDialog>
    <customDialog
      :customDialogData="customDialogData"
      @customDialogChildren="customDialogChildren"
    ></customDialog>
    <el-dialog title="业绩合同指标库" :visible.sync="dialogVisible" width="80%">
      <zhibiaoTable
        ref="zhibiaoRef"
        :hetongId="hetongId"
        @func="getRow"
      ></zhibiaoTable>
      <span slot="footer" class="dialog-footer">
        <el-button plain type="primary" @click="addZhibiao">添 加</el-button>
        <el-button plain @click="dialogVisible = false">取 消</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import {
  fetchListByNdId,
  delObj,
  putObj,
  submitjiaList,
  confirmStatus,
  confirmTianbao,
  conYtbfrac,
  confirmTianbaoAll,
  jgtbExportExcel,
  dataFormjiaSubmitAll,
  handleSubmitAll,
  handleSubmitAllByht,
  getListMb,
} from "@/api/hetongrenwu/hetongjgtb";
import { getnormlist } from "@/api/hetongrenwu/hetongzhibiaohz";
import { mapGetters } from "vuex";
import ElCol from "element-ui/packages/col/src/col";
import { getFormula } from "@/api/hetongrenwu/hetongyeji/hetongzb";
import customDialog from "@/views/hetongrenwu/hetong/hetongyeji/hetongnd/customDialog.vue";
import sortingPerChooseDialog from "@/views/hetongrenwu/components/sortingPerChooseDialog.vue";
import { fillInSub } from "@/api/hetongrenwu/hetongtbfq";
import contractDetailHeader from "@/views/hetongrenwu/components/contractDetailHeader";
import store from "@/store";
import request from "@/router/axios";
import { getStore } from "@/util/store";
import { saveZB } from "@/api/hetongrenwu/zhibiaoTable";
import zhibiaoTable from "@/views/hetongrenwu/hetong/hetongyeji/zhibiaoTable";
export default {
  components: {
    ElCol,
    sortingPerChooseDialog,
    customDialog,
    contractDetailHeader,
    zhibiaoTable,
  },
  props: {
    hetongzhibiaoTable: {},
    hetong: {},
    programInterface: "",
  },
  data() {
    return {
      pageTitle: "业绩合同",
      dataList: [],
      dataForm: {
        key: "",
      },
      temList: [],
      customDialogData: {},
      pageIndex: 1,
      pageSize: 10,
      totalPage: 0,
      dataListLoading: false,
      addOrUpdateVisible: false,
      radioTwo: "-1",
      zhibiaoForm: {},
      lastPage: "tbfq",
      showSearch: true,
      showBackBtn: true,
      visible: false,
      dataFormjia: {
        key: "",
        ytbSzfrac: 0,
        tbSzfrac: 0,
      },
      visiblejiakou: false,
      dataFormjiakou: {},
      status: Number,
      searchadvanced: true,
      searchheight: "0",
      formulaOptions: [],
      dialogVisiblePiLiang: false,
      fullscreenLoading: false,
      pilinangform: {},
      sortingPerChooseDialogData: {},
      jgtbstatus: "",
      taskId: "",
      chooseVisible: false,
      iszbsh: Number,
      fileList: [],
      dialogVisible: false,
      headers: {
        'TENANT-ID': getStore({ name: "tenantId" })
          ? getStore({ name: "tenantId" })
          : "1",
        Authorization: "Bearer " + store.getters.access_token,
      },
    };
  },
  watch: {
    hetongzhibiaoTable: {
      handler(newVal) {
        if (newVal) {
          this.hetongId = newVal.hetongId;
          this.str = newVal.str;
          this.ndId = newVal.ndId;
          if (newVal.rows) {
            this.taskId = newVal.rows.taskId;
          }
          this.getStatus(this.hetongId);
          this.fngetListMb();
        }
      },
      deep: true,
      immediate: true,
    },
    radio(value) {
      if (value) {
        this.getDataList();
      }
    },
  },
  created() {
    this.getFormula();
  },
  computed: {
    ...mapGetters(["permissions"]),
  },
  methods: {
    handleUploadSuccess(response, file, fileList) {
      var urls = "";
      if (this.lastPage == "jgtb") {
        urls = "/appr-contract/hetonghtzb/allocationFilejgtb1/";
      } else {
        urls = "/appr-contract/hetonghtzb/allocationFilejgtb/";
      }
      this.showExist = true;

      if (response.code !== 0) {
        this.$message.error("上传出错：" + response.msg);
        return;
      }
      this.bLoading = true;

      request({
        url: urls + response.data.bucketName + "/" + response.data.fileName,
        method: "get",
      })
        .then((res) => {
          this.getDataList();
          this.bLoading = false;
          this.$message.closeAll();
          this.$message.success("导入成功!");
        })
        .catch((error) => {
          this.bLoading = false;
        });
    },
    addZhibiao() {
      this.$refs.zhibiaoRef.saveZhibiao(this.dataList);
    },
    getRow(rows) {
      saveZB({ rows: rows, hetongId: this.hetongId, ndId: this.ndId }).then(
        (res) => {
          this.dialogVisible = false;
          this.getDataList();
        }
      );
    },
    beforeFileUpload(file) {
      ////console.log(file);
      const cType = file.type;
      let isXls = false;

      // const isXls = file.type === 'xls/xlsx';
      if (
        cType === "application/vnd.ms-excel" ||
        cType ===
          "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
      ) {
        isXls = true;
      }

      if (!isXls) {
        this.$message.error("导入文件只能是 Excel 格式!");
      }
      return isXls;
    },
    handleChange(file, fileList) {
      this.fileList = [];
      this.fileList.push(file);
    },
    showZhibiaoTable() {
      this.dialogVisible = true;
      this.$nextTick(() => {
        this.$refs.zhibiaoRef.init(this.hetongzhibiaoTable.type, 3);
        this.$refs.zhibiaoRef.getDataList();
      });
    },
    fngetListMb() {
      var params = {
        menuType: "结果填报",
        tagName: "业绩合同",
      };
      getListMb(params).then((res) => {
        this.temList = res.data.data;
      });
    },
    searchchangeadvanced() {
      this.searchadvanced = !this.searchadvanced;
      if (this.searchadvanced) {
        this.searchheight = "auto";
      }
    },
    customDialogChildren(data) {
      this.getDataList();
    },
    customBtn() {
      this.chooseVisible = false;
      this.customDialogData = {
        dialogVisible: true,
        type: 2,
        iszbsh: this.iszbsh,
        rows: this.hetong,
        menuType: "jgtb",
      };
    },
    temBtn(e) {
      this.fullscreenLoading = true;
      this.type = 1;
      var params = {
        type: this.type,
        isjgtbsh: this.iszbsh,
        rows: this.hetongzhibiaoTable.rows,
        templateId: e.id,
      };
      handleSubmitAll(params).then((res) => {
        this.fullscreenLoading = false;
        this.$message.closeAll();
        this.$message.success("操作成功");
        this.chooseVisible = false;
        this.getDataList();
      });
    },
    statusFormater(row, column) {
      const status = row.signLevel;
      if (status == 1) {
        return "一级合同";
      } else if (status == 2) {
        return "二级合同";
      } else if (status == 3) {
        return "三级合同";
      } else if (status == 4) {
        return "四级合同";
      } else if (status == 5) {
        return "五级合同";
      }
    },
    init(data) {
      this.lastPage = data.lastPage;
      this.showSearch = data.showSearch;
      this.pageTitle = data.pageTitle;
      this.showBackBtn = data.showBackBtn;
      this.ndId = data.ndId;
      // this.jgtbstatus=data.jgtbstatus;
      console.log(this.ndId + "===ndId0099999");
      this.getDataList();
    },
    // 获取数据列表
    getDataList() {
      //console.log(this.hetongzhibiaoTable.type+"===--type2222")
      this.dataListLoading = true;
      var params = {
        type: this.hetongzhibiaoTable.radioType,
        isbenbu: this.radioTwo,
        htId: this.hetongId,
        str: this.str,
        ndId: this.ndId,
        typedatas: this.hetongzhibiaoTable.type,
        zhibiaoName: this.dataForm.zhibiaoName,
        zhibiaoType: this.dataForm.zhibiaoType,
      };
      var params2 = {
        type: this.hetongzhibiaoTable.radioType,
        isbenbu: this.radioTwo,
        htId: this.hetongId,
        str: this.str,
        tbId: this.ndId,
        typedatas: this.hetongzhibiaoTable.type,
        zhibiaoName: this.dataForm.zhibiaoName,
        zhibiaoType: this.dataForm.zhibiaoType,
      };
      if (this.lastPage == "jgtb") {
        fetchListByNdId(params2).then((response) => {
          this.dataList = response.data.data.records;
          this.totalPage = response.data.data.total;
          this.dataListLoading = false;
        });
      } else {
        fetchListByNdId(params).then((response) => {
          this.dataList = response.data.data.records;
          this.totalPage = response.data.data.total;
          this.dataListLoading = false;
        });
      }
    },
    //获取状态
    getStatus(hetongId) {
      confirmStatus(hetongId).then((response) => {
        this.status = response.data.data;
      });
    },
    // 修改属性
    editProperty(row, index) {
      confirmStatus(this.hetongId).then((response) => {
        //console.log(response.data.data);
        this.status = response.data.data;
        this.$set(this.dataList[index], "isEditPropertyShow", true);
      });
    },
    // 保存属性
    saveProperty(row, index) {
      if (row.zhibiaoType == "奖惩类") {
        getnormlist({ normjks: row.zbDf, normid: row.zhibiaoId }).then(
          (res) => {
            if (res.data.data == 0) {
              // this.$message.closeAll();
              // this.$message.warning("超出加扣范围！");
              //  this.getDataList();

              this.$confirm(
                "您填写的得分已超出加扣范围，是否继续填写得分！",
                "提示",
                {
                  confirmButtonText: "确定",
                  cancelButtonText: "取消",
                  type: "warning",
                }
              )
                .then((res) => {
                  putObj(row)
                    .then((res) => {
                      this.$message.closeAll();
                      this.$message.success("保存成功！");
                    })
                    .then((res) => {
                      this.getDataList();
                    });
                })
                .catch((res) => {
                  this.getDataList();
                });
            } else {
              putObj(row).then((res) => {
                this.$message.closeAll();
                this.$message.success("保存成功！");
                //刷新列表
                this.getDataList();
              });
            }
          }
        );
      } else {
        putObj(row).then((res) => {
          this.$message.closeAll();
          this.$message.success("保存成功！");
          //刷新列表
          this.getDataList();
        });
      }
    },
    // 取消编辑
    cancelProperty(row, index) {
      this.$set(this.dataList[index], "isEditPropertyShow", false);
      this.getDataList();
    },
    // 每页数
    sizeChangeHandle(val) {
      this.pageSize = val;
      this.pageIndex = 1;
      this.getDataList();
    },
    // 当前页
    currentChangeHandle(val) {
      this.pageIndex = val;
      this.getDataList();
    },
    // 新增 / 修改
    addOrUpdateHandle(id) {
      this.addOrUpdateVisible = true;
      this.$nextTick(() => {
        this.$refs.addOrUpdate.init(id);
      });
    },
    // 删除
    deleteHandle(id) {
      this.$confirm("是否确认删除ID为" + id, "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(function () {
          return delObj(id);
        })
        .then((data) => {
          this.$message.closeAll();
          this.$message.success("删除成功");
          this.getDataList();
        });
    },
    //返回原来的页面
    fnBackOldPage(type) {
      this.$emit("fnBackOldPage", type);
    },
    //打开加扣维护弹框
    fnOpenJiaKou(obj) {
      confirmStatus(this.hetongId).then((response) => {
        //console.log(response.data.data);
        this.status = response.data.data;
        this.visible = true;
      });
      //判断之前是否填写过值
      conYtbfrac(obj.id).then((response) => {
        this.visible = true;
        this.dataFormjia = response.data.data;
      });
    },
    //关闭加扣维护弹框
    closeDialog() {
      this.visible = false;
      this.$refs["dataFormjia"].resetFields();
    },
    dataFormjiaSubmit(row, index) {
      submitjiaList(row).then((res) => {
        //刷新列表
        this.visible = false;
        this.$refs["dataFormjia"].resetFields();
        this.getDataList();
      });
    },
    confirmTianbao(data) {
      confirmTianbao(data).then((response) => {
        this.$message.closeAll();
        this.$message.success("提交成功");
        this.getDataList();
        document.getElementById("new_yan").style.cursor = "pointer";
      });
    },
    confirmTianbaoAll() {
      var rows = this.dataList;
      if (rows.length > 0) {
        var deptId = rows.map((item) => {
          return item.zbDeptId;
        });
        var ids = rows.map((item) => {
          return item.id;
        });
        var idsStr = ids.join(",");
        var deptIdStr = deptId.join(",");
        this.$confirm("是否要提交" + rows.length + "条结果?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        })
          .then(() => {
            var params = {
              ids: ids,
              ndDeptId: deptIdStr,
              htid: this.hetongId,
            };
            confirmTianbaoAll(params)
              .then((res) => {
                this.$message.closeAll();
                this.$message({
                  type: "info",
                  message: res.data.data + "条结果已通过",
                });
                this.getDataList();
              })
              .catch(() => {
                this.$message.closeAll();
                this.$message({
                  type: "error",
                  message: "提交失败!",
                });
                this.getDataList();
              });
          })
          .catch(() => {
            this.$message.closeAll();
            this.$message({
              type: "info",
              message: "已取消提交",
            });
          });
      } else {
        this.$message.closeAll();
        this.$message({
          type: "info",
          message: "请选择结果通过!",
        });
      }
    },
    fnOpenJiaKouAll() {
      this.visiblejiakou = true;
      this.dataFormjiakou = {
        key: "",
        tbSzfracs: 0,
      };
    },
    closeDialogAll() {
      this.visiblejiakou = false;
      this.$refs["dataFormjiakou"].resetFields();
    },
    dataFormjiaSubmitAll(row, index) {
      var rows = this.dataList;
      if (rows.length > 0) {
        dataFormjiaSubmitAll({
          htzbList: rows,
          tbSzfracs: row.tbSzfracs,
          tbSzfracres: row.tbSzfracres,
        })
          .then((res) => {
            this.$message.closeAll();
            this.$message({
              type: "info",
              message: res.data.data + "条指标已保存加扣分值",
            });
            this.getDataList();
            this.visiblejiakou = false;
          })
          .catch(() => {
            this.$message.closeAll();
            this.$message({
              type: "error",
              message: "保存失败!",
            });
            this.getDataList();
          });
      } else {
        this.$message.closeAll();
        this.$message({
          type: "info",
          message: "至少选择一条保存!",
        });
      }
    },

    //导出
    exportExcel() {
      var ids = [];
      ids.push(this.hetongId);
      var filename = "";
      if (ids.length > 1) {
        filename = "业绩合同结果填报.zip";
      } else {
        filename = "业绩合同结果填报" + this.hetong.contractName + ".xlsx";
      }
      console.log(this.ndId + "===" + this.hetongzhibiaoTable.type);
      jgtbExportExcel({
        ids: ids,
        type: this.hetongzhibiaoTable.type, //'jgtb'
        ndid: this.ndId,
      }).then((response) => {
        this.$message.closeAll();
        this.$message.success("导出成功!");
        let url = window.URL.createObjectURL(new Blob([response.data]));
        let link = document.createElement("a");
        link.style.display = "none";
        link.href = url;
        link.setAttribute("download", filename);
        document.body.appendChild(link);
        link.click();
      });
    },
    //公式
    getFormula() {
      getFormula().then((res) => {
        this.formulaOptions = res.data.data;
        // this.$set(this.dataList[index], 'isEditPropertyShow', true)
      });
    },
    tbzbStatusFormater(row, column) {
      const status = row.auditStatus;

      if (status == 0) {
        return "未提报";
      } else if (status == 1) {
        return "填报中";
      } else if (status == 2) {
        return "审核中";
      } else if (status == 3) {
        return "已经审核";
      } else if (status == 4) {
        return "审核驳回";
      } else if (status == 5) {
        return "结果填报中";
      } else if (status == 5) {
        return "结果填报完成";
      } else if (status == 7) {
        return "结果填报驳回";
      }
    },
    checkboxSelect(row, rowIndex) {
      //console.log(row.auditStatus)
      if (
        (this.lastPage == "tbfq" && row.contractAuditStatus == 10) ||
        (this.lastPage == "jgtb" && row.contractAuditStatus == 11) ||
        (this.lastPage == "tbsh" && row.contractAuditStatus == 12)
      ) {
        return true;
      } else {
        return false;
      }
    },
    //打开批量提交弹框
    openSubmitAllDialog() {
      if (this.lastPage == "jgtb") {
        this.$confirm("是否跳过结果审核", "提示", {
          confirmButtonText: "是",
          cancelButtonText: "否",
          type: "warning",
        })
          .then((res) => {
            this.iszbsh = 0;
            var params = {
              isjgtbsh: this.iszbsh,
              taskId: this.taskId,
              rows: this.hetong,
            };
            handleSubmitAll(params)
              .then((res) => {
                this.$message.closeAll();
                this.$message.success("提交成功");
                this.getDataList();
                this.fnBackOldPage("返回原页面");
              })
              .catch(() => {
                this.$message.closeAll();
                this.$message({
                  type: "error",
                  message: "提交失败!",
                });
              });
          })
          .catch(() => {
            this.iszbsh = 1;
            this.chooseVisible = true;
          });
      } else if (this.lastPage == "tbfq") {
        //this.$refs.reftable.selection.length > 0
        if (this.dataList.length > 0) {
          var params = {
            taskId: this.taskId,
            rows: this.dataList,
            istianbao: 1,
          };
          fillInSub(params).then((data) => {
            this.$message.closeAll();
            this.$message.success("提交成功");
            this.getDataList();
          });
        } else {
          this.$message.closeAll();
          this.$message({
            type: "info",
            message: "请选择合同发起填报!",
          });
        }
      } else {
        this.sortingPerChooseDialogData = {
          visible: true,
          rows: this.hetong,
          taskId: this.taskId,
          types: "jgtbde",
        };
      }
    },
    //批量提交
    handleSubmitAll() {
      this.$confirm("确定要提交指标么?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          var params = {
            rows: this.hetong,
            sonhq: this.pilinangform.sonhq,
          };
          if (this.lastPage == "jgtb") {
            handleSubmitAll(params)
              .then((res) => {
                this.dialogVisiblePiLiang = false;
                this.$message.closeAll();
                this.$message({
                  type: "info",
                  message: "已提交成功",
                });
                this.getDataList();
              })
              .catch(() => {
                this.$message.closeAll();
                this.$message({
                  type: "error",
                  message: "提交失败!",
                });
                this.getDataList();
              });
          } else {
            handleSubmitAllByht(params)
              .then((res) => {
                this.dialogVisiblePiLiang = false;
                this.$message.closeAll();
                this.$message({
                  type: "info",
                  message: "已提交成功",
                });
                this.getDataList();
              })
              .catch(() => {
                this.$message.closeAll();
                this.$message({
                  type: "error",
                  message: "提交失败!",
                });
                this.getDataList();
              });
          }
        })
        .catch(() => {
          this.$message.closeAll();
          this.$message({
            type: "info",
            message: "已取消提交",
          });
        });
    },
    sortingPerChooseDialogChild(data) {
      this.getDataList();
    },
  },
};
</script>
